﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils.Extention;
#region Version Info
/* ========================================================================
* 【本页面功能概述】
*
* 作者：wangjianfeng 创建时间：2012/7/31 21:00:46
* 文件名：Login.cs
*
* 修改者： 时间：
* 修改说明：
* ========================================================================
*/
#endregion
namespace ChinaLeg.Web.WebAdmin
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {

            if (txtUserName.Text.ToTrim().IsNullOrEmpty())
            {
                "用户名不能为空！".Alert();
                return;
            }
            if (txtPwd.Text.ToTrim().IsNullOrEmpty())
            {
                "密码不能为空！".Alert();
                return;
            }
            if (txtVcode.Text.ToTrim().IsNullOrEmpty())
            {
                "验证码不能为空！".Alert();
                return;
            }
            if (Session["CheckCode"] == null)
            {
                "验证码已超时，请重新输入！".Alert();
                return;
            }
            if (txtVcode.Text.ToTrim().ToLower() != Session["CheckCode"].ToString().ToLower())
            {
                "验证码输入错误！".Alert();
                return;
            }
            ChinaLeg.Model.Manager model = ChinaLeg.BLL.Manager.Instance.GetModel(txtUserName.Text);
            if (model == null)
            {
                "用户名不存在！".Alert();
            }
            else
            {
                
                if (model.PassWord == txtPwd.Text.ToTrim().MD5Encrypt())
                {
                    HttpCookie cookie = new HttpCookie("Login");
                    cookie.Value = Utils.Common.SerializeHelpercs.Serialize<ChinaLeg.Model.Manager>(model); ;
                    Response.Cookies.Add(cookie);
                    Response.Redirect("Main.aspx");
                }
                else
                {
                    "密码输入错误！".Alert();
                }
                
            }
        }
    }
}